package com.mengmeng.quicklymessage.widget;

import com.mengmeng.quicklymessage.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MessageDialog extends Dialog implements View.OnClickListener {

    public interface IMessageDialogOnClickListener {
        void OnClickListener(View v, String[] content);
    }

    private IMessageDialogOnClickListener onClick;
    private EditText mEditText;

    private Button okButton;

    public MessageDialog(Context context) {
        super(context);
        this.setTitle(context.getString(R.string.message_content));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.message_dialog);
        findView();
    }

    private void findView() {
        okButton = (Button) findViewById(R.id.okbutton);
        okButton.setOnClickListener(this);

        mEditText = (EditText) findViewById(R.id.editText);
    }

    public void setOnDialogOnClickListener(IMessageDialogOnClickListener l) {
        onClick = l;
    }

    @Override
    public void onClick(View v) {
        if (onClick != null) {
            Editable text = mEditText.getText();
            onClick.OnClickListener(v, new String[] { text.toString() });
            this.dismiss();
        }
    }
}
